<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :columns="tableColumns">
      <!--插槽:table标题-->
      <template #tableTitle>
        <span style="margin: 30px;width: 100%;">
          <a href="javascript:void(0)" @click="downloadFile('miniofile/templateFile/服务费用确认函模板.docx')" style="margin-right: 10px;"><Icon icon="ant-design:download-outlined" /> 服务费用确认函模板</a>
          <a-divider type="vertical"/>
          <a href="javascript:void(0)" @click="downloadFile('miniofile/templateFile/服务费用结算清单模板.xls')" style="margin-left: 10px;"><Icon icon="ant-design:download-outlined" /> 服务费用结算清单模板</a>
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <template #overlay>
              <a-menu>
                <a-menu-item key="1" @click="batchHandleDelete">
                  <Icon icon="ant-design:delete-outlined"></Icon>
                  删除
                </a-menu-item>
              </a-menu>
            </template>
            <a-button style="margin-left: 30px;">批量操作
              <Icon icon="mdi:chevron-down"></Icon>
            </a-button>
          </a-dropdown>
        </span>
        <br/>
        <div>
          <a-radio-group v-model:value="activeKey" button-style="solid" @change="handleRadioChange">
            <a-radio-button value="0">　待上传　</a-radio-button>
            <a-radio-button value="1">　审核中　</a-radio-button>
            <a-radio-button value="2">　审核通过　</a-radio-button>
            <a-radio-button value="3">审核拒绝（需重新上传）</a-radio-button>
          </a-radio-group>
        </div>
      </template>

      <!--操作栏-->
      <template #action="{ record }" v-if="ifShowActionColumn">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <!--成功数据插槽-->
      <template #successSlot="{record}">
        <span style="text-align: left;">
          <p>成功金额：<span>{{record.successAmount.toFixed(2)}}</span></p>
          <p>成功笔数：<span>{{record.successNum}}</span></p>
        </span>
      </template>
      <!--审核状态插槽-->
      <template #checkStatusSlot="{record}">
        <a-badge v-if="record.checkStatus==0" color="blue" :text="record.checkStatus_dictText" />
        <a-badge v-if="record.checkStatus==1" color="cyan" :text="record.checkStatus_dictText" />
        <a-badge v-if="record.checkStatus==2" color="green" :text="record.checkStatus_dictText" />
        <a-badge v-if="record.checkStatus==3" color="red" :text="record.checkStatus_dictText" />
      </template>
      <!--文件插槽-->
      <template #fileSlot="{text}">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <span v-else>
          <a-button :ghost="true" type="primary" preIcon="ant-design:search-outlined" size="small" @click="viewFile(text)">预览</a-button>
          <br/>
          <a-button style="margin-top: 10px;" :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">下载</a-button>
        </span>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <CaishuiTaskSettleListModal ref="registerModal" @success="handleSuccess"></CaishuiTaskSettleListModal>
  </div>
</template>

<script lang="ts" name="caishuiTaskSettleList-caishuiTaskSettleList" setup>
import { reactive, ref, computed } from "vue";
import { BasicTable, TableAction } from "/@/components/Table";
import { useListPage } from "/@/hooks/system/useListPage";
import { columns,columns1,columns2,columns3 } from "./CaishuiTaskSettleList.data";
import {
  batchDelete,
  deleteOne,
  getExportUrl,
  getImportUrl,
  list
} from "./CaishuiTaskSettleList.api";
import { downloadFile, viewFile } from "/@/utils/common/renderUtils";
import CaishuiTaskSettleListModal from "./components/CaishuiTaskSettleListModal.vue";

  const activeKey = ref('0');
  const queryParam = ref<any>({});
  const ifShowActionColumn = ref<boolean>(true);
  const registerModal = ref();
  const exportIconLoading = ref<boolean>(false);
  const tableColumns = ref<any>(columns);

  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '业务结算清单',
      api: list,
      canResize:false,
      useSearchForm: false,
      striped: true,
      showIndexColumn: true,
      ellipsis: false,
      showTableSetting: false,
      showActionColumn: ifShowActionColumn.value,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        params.checkStatus = activeKey.value;
        return Object.assign(params, queryParam.value);
      },
    },
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 改变单选框事件
   * @param e
   */
  function handleRadioChange(e){
     if(activeKey.value==='0'){
       tableColumns.value = columns;
       ifShowActionColumn.value = true;
     }else if(activeKey.value==='1'){
       tableColumns.value = columns.concat(...columns1);
       ifShowActionColumn.value = false;
     }else if(activeKey.value==='2'){
       tableColumns.value = columns.concat(...columns1,...columns2);
       ifShowActionColumn.value = false;
     }else if(activeKey.value==='3'){
       tableColumns.value = columns.concat(...columns1,...columns2,...columns3);
       ifShowActionColumn.value = true;
     };
    searchQuery();//查询
  }

  /**
   * 新增事件
   */
  function handleAdd() {
    registerModal.value.disableSubmit = false;
    registerModal.value.add();
  }
  
  /**
   * 编辑事件
   */
  function handleEdit(record: Recordable) {
    registerModal.value.disableSubmit = false;
    registerModal.value.edit(record);
  }
   
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    registerModal.value.disableSubmit = true;
    registerModal.value.edit(record);
  }
   
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteOne({ id: record.id }, handleSuccess);
  }
   
  /**
   * 批量删除事件
   */
  async function batchHandleDelete() {
    await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
  }
   
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
   
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '上传业务清单',
        icon: 'ant-design:upload-outlined',
        onClick: handleEdit.bind(null, record),
      },
    ];
  }
   
  /**
   * 下拉操作栏
   */
  function getDropDownAction(record) {
    return [
      {
        label: '详情',
        icon: 'ant-design:info-outlined',
        onClick: handleDetail.bind(null, record),
      }, {
        label: '删除',
        icon: 'ant-design:delete-outlined',
        popConfirm: {
          title: '是否确认删除？',
          confirm: handleDelete.bind(null, record),
        }
      }
    ]
  }

  /**
   * 查询
   */
  function searchQuery() {
    reload();
  }
  
  /**
   * 重置
   */
  function searchReset() {
    queryParam.value = {};
    selectedRowKeys.value = [];
    //刷新数据
    reload();
  }

  /**
   * 导出
   */
  function handleExportXls() {
    exportIconLoading.value = true;
    onExportXls();
  }

  /**
   * 导出成功回调
   */
  function exportXlsSuccess(data) {
    exportIconLoading.value = false;
  }




</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    margin-bottom: -10px;
    .table-page-search-submitButtons {
      display: block;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
